/*
 * Copyright 2017 ObjectBox Ltd. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.objectbox.index.model;


import io.objectbox.BoxStore;
import io.objectbox.Cursor;
import io.objectbox.Transaction;

// THIS CODE was originally GENERATED BY ObjectBox.

/**
 * Cursor for DB entity "EntityLongIndex".
 */
public final class EntityLongIndexCursor extends Cursor<EntityLongIndex> {

    // Property IDs get verified in Cursor base class
    private final static int __ID_indexedLong = EntityLongIndex_.indexedLong.id;
    private final static int __ID_float1 = EntityLongIndex_.float1.id;
    private final static int __ID_float2 = EntityLongIndex_.float2.id;
    private final static int __ID_float3 = EntityLongIndex_.float3.id;
    private final static int __ID_float4 = EntityLongIndex_.float4.id;
    private final static int __ID_float5 = EntityLongIndex_.float5.id;

    public EntityLongIndexCursor(Transaction tx, long cursor, BoxStore boxStore) {
        super(tx, cursor, EntityLongIndex_.__INSTANCE, boxStore);
    }

    @Override
    public long getId(EntityLongIndex entity) {
        return entity.getId();
    }

    /**
     * Puts an object into its box.
     *
     * @return The ID of the object within its box.
     */
    @Override
    public long put(EntityLongIndex entity) {
        Float float1 = entity.float1;
        int __id2 = float1 != null ? __ID_float1 : 0;
        Float float2 = entity.float2;
        int __id3 = float2 != null ? __ID_float2 : 0;
        Float float3 = entity.float3;
        int __id4 = float3 != null ? __ID_float3 : 0;

        collect002033(cursor, 0, PUT_FLAG_FIRST,
                __ID_indexedLong, entity.indexedLong, 0, 0,
                __id2, __id2 != 0 ? float1 : 0, __id3, __id3 != 0 ? float2 : 0,
                __id4, __id4 != 0 ? float3 : 0, 0, 0,
                0, 0, 0, 0);

        Float float4 = entity.float4;
        int __id5 = float4 != null ? __ID_float4 : 0;
        Float float5 = entity.float5;
        int __id6 = float5 != null ? __ID_float5 : 0;

        long __assignedId = collect002033(cursor, entity.id, PUT_FLAG_COMPLETE,
                0, 0, 0, 0,
                __id5, __id5 != 0 ? float4 : 0, __id6, __id6 != 0 ? float5 : 0,
                0, 0, 0, 0,
                0, 0, 0, 0);

        entity.setId(__assignedId);
        return __assignedId;
    }

}
